package com.lihao.wanandroid.ui.home.publicaccount

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.lihao.jetpackcore.base.BaseViewModel
import com.lihao.jetpackcore.ext.request
import com.lihao.jetpackcore.state.ResultState
import com.lihao.wanandroid.data.AppRepository
import com.lihao.wanandroid.data.model.ArticleResponse
import com.lihao.wanandroid.data.model.BasePageResponse
import com.lihao.wanandroid.data.model.PublicAccArticleResponse
import com.lihao.wanandroid.data.model.PublicAccTitleResponse

/**
 * Created by lihao on 2020/6/12.
 * Describe:公众号ViewModel
 */
class PublicAccountViewModel(application: Application) : BaseViewModel(application) {

    /**
     * 公众号标题
     */
    val publicAccTitle: MutableLiveData<ResultState<ArrayList<PublicAccTitleResponse>>> =
        MutableLiveData()

    /**
     * 公众号文章
     */
    val publicAccArticle: MutableLiveData<ResultState<BasePageResponse<ArticleResponse>>> =
        MutableLiveData()

    var curAccount: String = ""

    var pageNo: Int = 1

    fun getPublicAccTitle() {
        pageNo = 1
        request(
            { AppRepository.getPublicAccount() },
            publicAccTitle
        )
    }

    fun getPublicAccArticle(isRefresh: Boolean) {
        if(isRefresh){
            pageNo = 1
        }
        request({ AppRepository.getPublicData(curAccount, pageNo) }, publicAccArticle)
    }
}